package per.jdz.demo.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import per.jdz.demo.config.HuoshanDoubaoConfig;
import per.jdz.demo.domain.dto.HouseDTO;
import per.jdz.demo.domain.entity.SecondHouseDataRename;
import per.jdz.demo.service.DouBaoService;

import javax.annotation.Resource;

/**
 * @author Jdz
 * @date 2025/1/6
 */
@Service
@Slf4j
public class DouBaoServiceImpl implements DouBaoService {
    @Resource
    HuoshanDoubaoConfig doubaoConfig;

    private final String SERVICE_URL = "http://127.0.0.1:5050/crawler/human";
    @Override
    public String getProjectName(HouseDTO houseData) {
       /* String apiKey = doubaoConfig.getApiKey();
        ArkService service = ArkService.builder().apiKey(apiKey).build();
        final List<ChatMessage> messages = new ArrayList<>();
        final ChatMessage systemMessage = ChatMessage.builder().role(ChatMessageRole.SYSTEM).content("你是一个房产名查找助手，你需要根据用户提供的楼盘信息从网上找到对应的具体楼盘地址，并输出给用户，只需要输出具体的楼盘的名称即可").build();*/
        String human = String.format("根据这些信息：济南市,%s,%s,%s,%s，查出具体的楼盘名称叫什么，只输出楼盘名称，不要有多余的输出，没有就输出抱歉", houseData.getProjectName(), houseData.getPreSaleLicenseNumber(), houseData.getDeveloper(), houseData.getProjectAddress());
        System.out.println(human);
        RestTemplate restTemplate = new RestTemplate();
        String url = String.format(SERVICE_URL + "/%s", human);
        String body = restTemplate.getForEntity(url, String.class).getBody();
        if (StringUtils.hasLength(body)) body = body.replace("\"", "");
        log.info("{}", body);
        return body;
    }

    @Override
    public String getCommunityName(SecondHouseDataRename secondHouseDataRename) {
        String human = String.format("济南市,%s,%s,%s,%s，具体的楼盘名称是什么，只要输出楼盘名称", secondHouseDataRename.getCommunityName(),
                secondHouseDataRename.getDistrict(), secondHouseDataRename.getArea(), secondHouseDataRename.getAddress());
        System.out.println(human);
        RestTemplate restTemplate = new RestTemplate();
        String url = String.format("http://127.0.0.1:5555/human/%s", human);
        String body = restTemplate.getForEntity(url, String.class).getBody();
        if (StringUtils.hasLength(body)) body = body.replace("\"", "");
        System.out.println(body);
        return body;
    }
}
//        final ChatMessage userMessage = ChatMessage.builder().role(ChatMessageRole.USER).content(human).build();
//        messages.add(systemMessage);
//        messages.add(userMessage);
//
//        BotChatCompletionRequest chatCompletionRequest = BotChatCompletionRequest.builder()
//                // 将<YOUR_BOT_ID>替换为您的应用ID
//                .model(doubaoConfig.getModelName())
//                .messages(messages)
//                .build();
//
//        BotChatCompletionResult chatCompletionResult = service.createBotChatCompletion(chatCompletionRequest);
//        Object content = chatCompletionResult.getChoices().get(0).getMessage().getContent();
//        return content.toString();